<?php $pref = md5($vid.$cr.$co.$ca); ?>
<canvas id="myCanvas<?php echo $pref;?>" width="<?php echo $vwidth;?>" height="<?php echo $vheight;?>" style="border:1px solid #c3c3c3;">
    Your browser does not support the canvas element.
</canvas>

<?php if(isset($btnplayisvisible)?$btnplayisvisible:TRUE){ ?>
    <input type="button" id="<?php echo 'bp'.md5('btn_play'.$pref); ?>" value="Play" onclick="<?php echo 'p'.md5('playVideo'.$pref);?>()"/>
<?php } ?>

<script type="text/javascript">
    var c<?php echo $pref;?> = document.getElementById("myCanvas<?php echo $pref;?>");
    var ctx<?php echo $pref;?> = c<?php echo $pref;?>.getContext("2d");
    var img<?php echo $pref;?> = new Image();
    var url<?php echo $pref;?> = '';
    <?php $blankURL = Appglobalparameters::model()->find("parametername='BLANK_URL' and isactive = TRUE"); ?>
    var blankUrl<?php echo $pref;?> = '<?php echo isset($blankURL)?$blankURL->value:''; ?>';
    var tplay<?php echo $pref;?>;
    var tregis<?php echo $pref;?>;
    var st<?php echo $pref;?> = new Date();    
    var ap<?php echo $pref;?> = <?php echo isset($autoplay)?$autoplay:false; ?>;
    
    function refreshImage<?php echo $pref;?>() {
        if(url<?php echo $pref;?>.trim() === ''){
            $.ajax ({
            type:"POST",
            url:"<?php echo Yii::app()->createUrl('/specialajax/requestCurrentURL'); ?>",
            data:"cr=<?php echo $cr; ?>&co=<?php echo $co; ?>&ca=<?php echo $ca; ?>",
            dataType:"json",
                success:function(data){
                    url<?php echo $pref;?> = data;
                }
            });
        }
        
        if (url<?php echo $pref;?>.trim() === ''){
            img<?php echo $pref;?>.src = blankUrl<?php echo $pref;?>;
            ctx<?php echo $pref;?>.drawImage(img<?php echo $pref;?>, 0, 0, <?php echo $vwidth;?>, <?php echo $vheight;?>);
            url<?php echo $pref;?>='';
        }else{
            img<?php echo $pref;?>.src = url<?php echo $pref;?>+'?t='+ new Date().getTime();
            ctx<?php echo $pref;?>.drawImage(img<?php echo $pref;?>, 0, 0, <?php echo $vwidth;?>, <?php echo $vheight;?>);
            ctx<?php echo $pref;?>.fillStyle = 'white';
            ctx<?php echo $pref;?>.font = "Bold 12px Arial";
            var of<?php echo $pref;?> = new Date().getTimezoneOffset();
            of<?php echo $pref;?> = ((of<?php echo $pref;?><0?-1:+1)*(parseInt(of<?php echo $pref;?>/60)));
            var el<?php echo $pref;?> = new Date(new Date() - st<?php echo $pref;?>-(of<?php echo $pref;?>*1000*60*60));
            var j<?php echo $pref;?> = (el<?php echo $pref;?>.getHours()<10?'0'+el<?php echo $pref;?>.getHours():el<?php echo $pref;?>.getHours()) + ":"
                    +(el<?php echo $pref;?>.getMinutes()<10?'0'+el<?php echo $pref;?>.getMinutes():el<?php echo $pref;?>.getMinutes()) + ":"
                    +(el<?php echo $pref;?>.getSeconds()<10?'0'+el<?php echo $pref;?>.getSeconds():el<?php echo $pref;?>.getSeconds());
            
            <?php if (isset($showtimeinfo)?$showtimeinfo:FALSE){ ?>
                ctx<?php echo $pref;?>.fillText(j<?php echo $pref;?>, 0, <?php echo $vheight-12;?>);
                ctx<?php echo $pref;?>.fillText(new Date().toDateString() + ', ' + new Date().toTimeString(), 0, <?php echo $vheight;?>);
            <?php } ?>
        }
    }

    function regisExpired<?php echo $pref;?>(){
        $.ajax ({
        type:"POST",
        url:"<?php echo Yii::app()->createUrl('/specialajax/updateexpired'); ?>",
        data:"cr=<?php echo $cr; ?>&co=<?php echo $co; ?>&ca=<?php echo $ca; ?>",
        dataType:"json",
        });
    }
    
    function <?php echo 'p'.md5('playVideo'.$pref); ?>(){
        if ($('#<?php echo 'bp'.md5('btn_play'.$pref); ?>').val() == 'Play'){
            tplay<?php echo $pref;?> = setInterval('refreshImage<?php echo $pref;?>()', <?php echo $vinterval; ?>);
            tregis<?php echo $pref;?> = setInterval("regisExpired<?php echo $pref;?>()", 30000);

            st<?php echo $pref;?> = new Date();
            $('#<?php echo 'bp'.md5('btn_play'.$pref); ?>').val('Stop');
        }else if ($('#<?php echo 'bp'.md5('btn_play'.$pref); ?>').val() == 'Stop'){
            clearInterval(tplay<?php echo $pref;?>);
            clearInterval(tregis<?php echo $pref;?>);

            $('#<?php echo 'bp'.md5('btn_play'.$pref); ?>').val('Play');
        }
    }

    $(document).ready(function(){
        img<?php echo $pref;?>.src = blankUrl<?php echo $pref;?>;
        ctx<?php echo $pref;?>.drawImage(img<?php echo $pref;?>, 0, 0, <?php echo $vwidth;?>, <?php echo $vheight;?>);
        url<?php echo $pref;?>='';
        
        if (ap<?php echo $pref;?>){
            tplay<?php echo $pref;?> = setInterval('refreshImage<?php echo $pref;?>()', <?php echo $vinterval; ?>);
            tregis<?php echo $pref;?> = setInterval("regisExpired<?php echo $pref;?>()", 30000);

            st<?php echo $pref;?> = new Date();
        }
    });
</script>